<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h1><%= title%></h1>
  name:<input type="text" class="name"> <br>
  gender: <input type="text" class="gender"> <br>
  address: <input type="text" class="address"> <br>
  date: <input type="date" class="date"> <br>
  <button class="btn">添加数据成功跳转到产品页面</button>
  <script src="js/axios.js"></script>
  <script>

    const btn = document.querySelector('.btn')
    const name = document.querySelector('.name')
    const gender = document.querySelector('.gender')
    const address = document.querySelector('.address')
    const date = document.querySelector('.date')
    btn.onclick = function () {
      if (name.value && gender.value && address.value && date.value) {
        axios.post('/api/add', {
          name: name.value.trim(),
          gender: gender.value.trim(),
          address: address.value.trim(),
          date: date.value.trim(),
        })
          .then(res => {
            console.log(res, 'res')
            if (res.data.code === 0) {
              window.location.href = './product'
            }
          })
      }
    }


  </script>

</body>

</html>